package com.adminx.dao;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.adminx.entity.Message;
import com.adminx.util.PageResults;

@Repository
public class MessageDao extends BaseDao<Message, Long>{
	
	protected static Logger LOGGER = Logger.getLogger(MessageDao.class); 
	
	/**
	 * 分页查找�?
	 */
	public PageResults<Message> query(Integer pageIndex, Integer pageSize){
		if(pageIndex == null){
			pageIndex = 1;
		}
		if(pageSize == null){
			pageSize = 10;
		}
		String hql = "From Message c";
		String countHql = "select count(*) from Message c";
		PageResults<Message> messages = this.findPageByFetchedHql(hql, countHql, pageIndex, pageSize);
		return messages;
	}
	
	/**
	 * 批量删除
	 * @param authorityId
	 */
	public int delBatch(String ids) {
		
		String[] idsArray = ids.split(",");
		String hql = "";
		for (int i = 0; i < idsArray.length; i++) {
			if (i == 0) {
				hql = "messageId=" + idsArray[i];
			} else {
				hql = hql + " or messageId=" + idsArray[i];
			}
		}
		int updateCount = this.getSession().createQuery("DELETE FROM Message WHERE " + hql).executeUpdate();
		return updateCount;
	}
	
}
